/**
 * 部门管理初始化
 */
var Customer = {
    id: "CustomerTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

/**
 * 初始化表格的列
 */
Customer.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle',},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle',},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true,width:120,},
        {
            title: '姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Customer.openBilee(" + '"' + row.id + '"' + ")'>" + row.customerName + "</a>"
            }                       
        },
        // {title: '化名', field: 'pseudonym', align: 'center', valign: 'middle', sortable: true,},
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true,width:120,},
        {title: '使用人', field: 'phoneSharShip', align: 'center', valign: 'middle', sortable: true,width:120},
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                } else {
                    return "未知"
                }
            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true,width:120},
        // {title: '生日', field: 'birthday', align: 'center', valign: 'middle', sortable: true, width: '17%',},
        {
            title: '咨询项目', field: 'appointmentPayService', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                if (value == "" || value == null) {
                    return "<a href='javascript:;' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                } else {
                    return "<a href='javascript:;' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>" + value.replace(reg, ' ') + "</a>"
                }
            }
        },
        {title: '一级渠道', field: 'oneChannel', align: 'center', valign: 'middle', sortable: true,width:120},
        {title: '二级渠道', field: 'twoChannel', align: 'center', valign: 'middle', sortable: true,width:120},
        {title: '三级渠道', field: 'thrChannel', align: 'center', valign: 'middle', sortable: true,width:120},
        {
            title: '客户状态', field: 'customerStatus', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                if (value == "作废") {
                    return "<a href='javascript:;' onclick='Customer.ToVoidDetails(" + '"' + row.id + '"' + ")'>[作废]</a>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '成交状态', field: 'dealStatus', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                if (value == "已成交") {
                    return "<a href='javascript:;' onclick='Customer.opendealStatus(" + '"' + row.reservationsId + '"' + ")'>[已成交]</a>"
                } else if (value != "已成交") {
                    return "未成交";
                }
            }
        },
        {title: '缴费金额', field: 'actualAccountBalance', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Customer.reviseAccountBalance("+'"'+row.reservationsId+'","'+row.actualAccountBalance+'"'+")'>" + row.actualAccountBalance + "</a>"
            }
        },
        // {title: '赠送余额', field: 'giveAccountBalance', align: 'center', valign: 'middle', sortable: true},
        {title: '欠费', field: 'accountArrears', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Customer.reviseArrears("+'"'+row.reservationsId+'","'+row.accountArrears+'"'+")'>" + row.accountArrears + "</a>"
            }
        },
        {
            title: '现场TC', field: 'fieldTc', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                if (value == "" || value == null) {
                    return "<a href='javascript:;' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                } else {
                    return "<a href='javascript:;' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>" + value + "</a>"
                }
            }
        },
        {
            title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                return value.replace(reg, ' ');
            }
        },
        {
            title: '医助/护士', field: 'nurse', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                return value.replace(reg, ' ');
            }
        },
        {
            title: '到店时间', field: 'arrivalTime', align: 'center', valign: 'middle', sortable: true,width:120,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {
            title: '初诊时间', field: 'firstVisitDate', align: 'center', valign: 'middle', sortable: true,width:120,
        },
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true,width:120},
    ]
    return columns;
};


Customer.openRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '成交操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.choiceTc = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择Tc',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choiceTc/' + id
    });
    this.layerIndex = index;
};

Customer.choiceAppointment = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择咨询项目',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choiceAppointment/' + id
    });
    this.layerIndex = index;
};

Customer.opendealStatus = function (id) {
    $.ajax({
        url: Feng.ctxPath + "/reservations/getTotleMoneys",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            alert("成交金额：" + data + "元");
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


/**
 * 点击发短信
 */
Customer.msgSend = function () {
   var customerId=document.getElementById("customerId").value;
    var customerName=document.getElementById("customerName").value;
    var customerPhone=document.getElementById("customerPhone").value;
    var messageContent=document.getElementById("message_content").value;
    if (confirm("发送信息给【" + customerName + "】?")) {
        $.ajax({
            url: Feng.ctxPath + "/msgSend/msgSend",
            type: "post",
            data: {
                customerId: customerId,
                messageContent: messageContent,
                customerPhone: customerPhone
            },
            success: function (data) {
                Feng.success('操作成功!');
                Customer.close();
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};

Customer.openBilee = function (ide) {
    var index = layer.open({
        type: 2,
        title: '到店客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileLists/' + ide
    });
    this.layerIndex = index;
};

Customer.reviseArrears = function (id,accountArrears) {
    var ia = id + "," + accountArrears;
    var index = layer.open({
        type: 2,
        title: '修改欠费',
        area: ['60%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_accountArrears/' + ia
    });
    this.layerIndex = index;
};

Customer.reviseAccountBalance = function (id,actualAccountBalance) {
    var ia = id + "," + actualAccountBalance;
    var index = layer.open({
        type: 2,
        title: '修改缴费',
        area: ['60%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_actualAccountBalance/' + ia
    });
    this.layerIndex = index;
};

Customer.ToVoidDetails = function (id) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/toVoidDetails/' + id
    });
    this.layerIndex = index;
};

Customer.openAddVisited = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_addVisited/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.openRecharge = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加充值',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/recharge/to_recharge/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.specialSupplement = function () {
    if (this.check()) {
        var reservationsId = Customer.seItem.reservationsId;
        var customerId = Customer.seItem.id;
        var rc = reservationsId + "," + customerId;
        var index = layer.open({
            type: 2,
            title: '特殊补款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/recharge/to_specialSupplement/' + rc
        });
        this.layerIndex = index;
    }
};

Customer.specialRefund = function () {
    if (this.check()) {
        var reservationsId = Customer.seItem.reservationsId;
        var customerId = Customer.seItem.id;
        var rc = reservationsId + "," + customerId;
        var index = layer.open({
            type: 2,
            title: '特殊退款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/refund/to_specialRefund/' + rc
        });
        this.layerIndex = index;
    }
};

Customer.addSpecialRefund = function () {
    var customerId = $("#customerId").val();
    var reservationsId = $("#reservationsId").val();
    var refundMoney = $('#refundMoney').val();
    var remarks = $('#remarks').val();
    var refundsType = $('#refundsType').val();
    if (refundMoney == null || refundMoney == "") {
        alert("请输入退款金额！");
        return
    }
    if (remarks == null || remarks == "") {
        alert("请输入备注！");
        return
    }
    if (!(/^[0-9]{1}\d{0,6}(\.\d{1,2})?$/.test(refundMoney))) {
        alert("请输入正确金额！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/refund/addSpecialRefund",
        type: "post",
        data: {
            "customerId": customerId,
            "reservationsId": reservationsId,
            "remarks": remarks,
            "refundsType": refundsType,
            "refundMoney": refundMoney
        },
        success: function (data) {
            Feng.success("操作成功!");
            window.parent.Customer.table.refresh();
            Customer.close();
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
}

Customer.addSpecialSupplement = function () {
    var customerId = $("#customerId").val();
    var reservationsId = $("#reservationsId").val();
    var supplementMoney = $('#supplementMoney').val();
    var remarks = $('#remarks').val();
    if (supplementMoney == null || supplementMoney == "") {
        alert("请输入补费金额！");
        return
    }
    if (remarks == null || remarks == "") {
        alert("请输入备注！");
        return
    }
    if (!(/^[0-9]{1}\d{0,6}(\.\d{1,2})?$/.test(supplementMoney))) {
        alert("请输入正确金额！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/recharge/addSpecialSupplement",
        type: "post",
        data: {
            "customerId": customerId,
            "reservationsId": reservationsId,
            "remarks": remarks,
            "supplementMoney": supplementMoney
        },
        success: function (data) {
            Feng.success("操作成功!");
            window.parent.Customer.table.refresh();
            Customer.close();
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
}

Customer.close = function () {
    // parent.layer.close(window.parent.Customer.layerIndex);
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

Customer.openRefund = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加退款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/refund/to_refund/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.openNoRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '成交操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openNoRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.uploadCustomer = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_import/'
    });
    this.layerIndex = index;
};

Customer.openRevisitRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_revisitRecord/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.revisitOperation = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_revisitOperation/' + reservationsId
    });
    this.layerIndex = index;
};

/**
 * 检查是否选中
 */
Customer.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Customer.seItem = selected[0];
        return true;
    }
};

/**
 * 打开重新咨詢
 */
Customer.openReconsulting = function (id) {
    var index = layer.open({
        type: 2,
        title: '再次到店咨詢',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_reconsulting/' + id
    });
    this.layerIndex = index;
};

/**
 * 点击预约客户
 */
Customer.openAddNature = function () {
    var index = layer.open({
        type: 2,
        title: '添加到店客户',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_nature_courtyard_add/' + document.getElementById("customerPhone").value
    });
    this.layerIndex = index;
};

Customer.openAddNatures = function () {
    var index = layer.open({
        type: 2,
        title: '添加到店客户',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_nature_courtyard_addd/' + document.getElementById("customerPhone").value
    });
    this.layerIndex = index;
};

/**
 * 打开查看到店客户详情
 */
Customer.openCustomerDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '到店客户详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/customer_update/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.openCustomerDetails = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_details/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.openCustomerDetailss = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_details/' + id
    });
    this.layerIndex = index;
};

/**
 * 作废预约客户
 */
Customer.openToVoid = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '作废备注',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/openToVoid/' + Customer.seItem.id
        });
    }
};

/**
 * 统计总人数
 */
Customer.total = function () {
    var startArrivalTime = $("#startArrivalTime").val();  //到诊开始时间
    var endArrivalTime = $("#endArrivalTime").val();   //到诊结束时间
    var oneChannelValue = $("#oneChannel").val();  // 一级渠道
    var twoChannelValue = $("#twoChannel").val(); //二级渠道
    var thrChannelValue = $("#thrChannel").val(); //三级渠道
    var dealStatus = $("#dealStatus").val(); //成交状态
    var appointmentPayService = $("#appointmentPayService").val();
    var reach = $("#reach").val();
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/customer/total",
        data: {
            appointmentPayService: appointmentPayService,
            startArrivalTime: startArrivalTime,
            endArrivalTime: endArrivalTime,
            oneChannelValue: oneChannelValue,
            twoChannelValue: twoChannelValue,
            thrChannelValue: thrChannelValue,
            reach:reach,
            dealStatus: dealStatus
        },
        dataType: "json",
        success: function (data) {
            $("#total").html(data[0].countNum);//总人数
            $("#first").html(data[1].countNum);//新客首次
            $("#secondary").html(data[2].countNum);//新客二次
            $("#oldGuest").html(data[3].countNum);//老客
            $("#revisit").html(data[4].countNum);//复诊

            $("#totalMoney").html(data[0].actualAccountBalanceNum);//总金额
            $("#firstMoney").html(data[1].actualAccountBalanceNum);//新客首次金额
            $("#secondaryMoney").html(data[2].actualAccountBalanceNum);//新客二次金额
            $("#oldGuestMoney").html(data[3].actualAccountBalanceNum);//老客金额
            $("#revisitMoney").html(data[4].actualAccountBalanceNum);//复诊金额
        }
    });
}

//总人数数据详情
Customer.totalNumber = function () {
    document.getElementById("customerStatus").value = "";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//到诊开始时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//到诊结束时间
    queryData['oneChannel'] = $("#oneChannel").val();// 一级渠道
    queryData['twoChannel'] = $("#twoChannel").val();//二级渠道
    queryData['thrChannel'] = $("#thrChannel").val();//三级渠道
    queryData['dealStatus'] = $("#dealStatus").val();//成交状态
    queryData['reach'] = $("#reach").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['customerStatus'] = ""; //加入客户状态，总人数
    Customer.table.refresh({query: queryData});
};
//新客首次数据详情
Customer.newCustomsData = function () {
    document.getElementById("customerStatus").value = "新客首次";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['oneChannel'] = $("#oneChannel").val();// 跟踪状态
    queryData['twoChannel'] = $("#twoChannel").val();//消费状态
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['customerStatus'] = "新客首次";//加入客户状态，新客首次
    Customer.table.refresh({query: queryData});
};
//新客二次数据详情
Customer.newSecondary = function () {
    document.getElementById("customerStatus").value = "新客二次";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['oneChannel'] = $("#oneChannel").val();// 跟踪状态
    queryData['twoChannel'] = $("#twoChannel").val();//消费状态
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['customerStatus'] = "新客二次";//加入客户状态，新客二次
    Customer.table.refresh({query: queryData});
};
//老客数据详情
Customer.newOldGuest = function () {
    document.getElementById("customerStatus").value = "老客";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['oneChannel'] = $("#oneChannel").val();// 跟踪状态
    queryData['twoChannel'] = $("#twoChannel").val();//消费状态
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['customerStatus'] = "老客";//加入客户状态，老客
    Customer.table.refresh({query: queryData});
};
//复诊数据详情
Customer.newRevisit = function () {
    document.getElementById("customerStatus").value = "复诊";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['oneChannel'] = $("#oneChannel").val();// 跟踪状态
    queryData['twoChannel'] = $("#twoChannel").val();//消费状态
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};

/**
 * 查询预约客户列表
 */
Customer.inquire = function () {
    Customer.search();
};

Customer.search = function () {
    Customer.table.refresh({query: Customer.formParams()});
    Customer.total();
};

Customer.backVisitSearch = function () {
    Customer.table.refresh({query: Customer.formParamsS()});
};

// var parseParam = function (param, key) {
//     var paramStr = "";
//     if (param instanceof String || param instanceof Number || param instanceof Boolean) {
//         paramStr += "&" + key + "=" + param;
//     } else {
//         $.each(param, function (i) {
//             var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
//             paramStr += '&' + parseParam(this, k);
//         });
//     }
//     return paramStr.substr(1);
// };
var parseParam = function (param) {
    var paramStr = "";

    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
};


Customer.downLoad = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['oneChannel'] = $("#oneChannel").val();
    queryData['twoChannel'] = $("#twoChannel").val();
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['backVisit'] = $("#backVisit").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/customer/customerExport?' + param;
}

Customer.formParamsS = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['reservations'] = $("#reservations").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['doctor'] = $("#doctor").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    queryData['oneChannel'] = $("#oneChannel").val();
    queryData['twoChannel'] = $("#twoChannel").val();
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    document.getElementById("backVisit").value = "1";
    queryData['backVisit'] = "1";
    return queryData;
}

Customer.resetSearch = function () {
    $("#reach").val("");
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#appointmentPayService").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("请选择");
    $("#twoChannel").val("请选择");
    $("#thrChannel").val("请选择");
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.reservationMatching = function () {
    var customerPhone = $('#customerPhone').val();
    var customerName = $('#customerName').val();
    var pn;
    if (!(/^\d{5,13}$/).test(customerPhone)) {
        alert("电话为5到13位的数字，请重新输入...");
        return;
    }
    if (customerPhone == null || customerPhone == "") {
        alert("请输入电话号码！");
        return;
    }
    var index = layer.open({
        type: 2,
        title: '预约客户电话匹配',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_reservation_matching/' + customerPhone
    });
    this.layerIndex = index;
};

/*
导入预约查询明细
 */
Customer.inputInfo = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/recharge/customerInfo_import/'
    });
    this.layerIndex = index;
};

Customer.todayNew = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#appointmentPayService").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("customerStatus").value = "新客首次"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.todayDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#appointmentPayService").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("dealStatus").value = "已成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.todayNoDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("dealStatus").value = "未成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.monthDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("dealStatus").value = "已成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthNoDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("dealStatus").value = "未成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthNew = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#appointmentPayService").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#dealStatus").val("");
    $("#customerStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("customerStatus").value = "新客首次"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthReview = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#appointmentPayService").val("");
    $("#doctor").val("");
    $("#dealStatus").val("");
    $("#customerStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("customerStatus").value = "复诊"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.todayReview = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#dealStatus").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#appointmentPayService").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("customerStatus").value = "复诊"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Customer.formParams = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['reservations'] = $("#reservations").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['doctor'] = $("#doctor").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    queryData['oneChannel'] = $("#oneChannel").val();
    queryData['twoChannel'] = $("#twoChannel").val();
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    document.getElementById("backVisit").value = "";
    queryData['backVisit'] = "";
    return queryData;
};

$(function () {
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = Customer.initColumn();
    var table = new BSTable(Customer.id, "/customer/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Customer.formParams());
    Customer.table = table.init();
    Customer.search();
    // Customer.total();

    //采用定时器监听 时间内容是否变化
    var startArrivalTimeTwo = $("#startArrivalTime").val();
    var endArrivalTimeTwo = $("#endArrivalTime").val();

    var oldOneChannelValue = $("#oneChannel").val();
    var oldTwoChannelValue = $("#twoChannel").val();
    var oldThrChannelValue = $("#thrChannel").val();
    var oldAppointmentPayServiceValue = $("#appointmentPayService").val();
    setInterval(
        function () {//定时执行方法内容
            if ($("#startArrivalTime").val() != startArrivalTimeTwo || $("#endArrivalTime").val() != endArrivalTimeTwo) {//如果时间发生变化，就触发查询事件
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                startArrivalTimeTwo = $("#startArrivalTime").val();
                endArrivalTimeTwo = $("#endArrivalTime").val();
            }
            if ($("#appointmentPayService").val() != oldAppointmentPayServiceValue || $("#appointmentPayService").val() != oldAppointmentPayServiceValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldAppointmentPayServiceValue = $("#appointmentPayService").val();
            }
            if ($("#oneChannel").val() != oldOneChannelValue || $("#oneChannel").val() != oldOneChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldOneChannelValue = $("#oneChannel").val();
            }
            if ($("#twoChannel").val() != oldTwoChannelValue || $("#twoChannel").val() != oldTwoChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldTwoChannelValue = $("#twoChannel").val();
            }
            if ($("#thrChannel").val() != oldThrChannelValue || $("#thrChannel").val() != oldThrChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldThrChannelValue = $("#thrChannel").val();
            }

        }, 500);
});
